package com.pearl.jacksoncore.demo.databind.anno;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;

/**
 * @author TD
 * @version 1.0
 * @date 2024/4/15
 */
public class AnnotationIntrospectorTest {


    public static void main(String[] args) throws JsonProcessingException {

        IntrospectorVO vo = new IntrospectorVO("阿坤", 1767798780627279333L);
        ObjectMapper objectMapper = new ObjectMapper();
        // objectMapper.setAnnotationIntrospector(NopAnnotationIntrospector.nopInstance()); // 关闭注解
        //objectMapper.setAnnotationIntrospector(new CustomJacksonAnnotationIntrospector());
        objectMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(
                objectMapper.getSerializationConfig().getAnnotationIntrospector(), // jackson 原有的
                MyAnnotationIntrospector.instance // 自定义的作为辅助方案
        ));
        String jsonStr = objectMapper.writeValueAsString(vo);
        System.out.println(jsonStr);
    }
}
